package com.qf.work.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.work.entity.Workorder;
import com.qf.work.mapper.WorkorderMapper;
import com.qf.work.service.WorkorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkorderServiceImpl implements WorkorderService {

    @Autowired
    private WorkorderMapper workorderMapper;

    @Override
    public void insert(Workorder workorder) {
        int i = workorderMapper.insertSelective(workorder);
        if(i!=1){
            System.out.println("【添加工单信息】添加失败！");
            throw new RuntimeException("【添加工单信息】添加失败！");
        }
    }

    @Override
    public List<Workorder> findAll() {
        List<Workorder> workorderList = workorderMapper.selectByExample(null);
        return workorderList;
    }

    @Override
    public PageInfo<Workorder> findByProjectIdAndPage(Integer page, Integer rows, Long projectId) {
        //1、分页
        PageHelper.startPage(page, rows);

        //2、查询
        List<Workorder> workorderList=workorderMapper.findByProjectId(projectId);

        //3、封装PageInfo
        PageInfo<Workorder> pageInfo = new PageInfo<>(workorderList);

        //4、返回
        return pageInfo;
    }
}
